<template>
	<view class="entryLook">
		<!-- 材料入库 --- 查看记录 -->
		<baseInput @inputChange='inputChange'></baseInput>
		<view class="content">
			<scroll-view class="content-scoll" scroll-y='true' @scrolltolower='scrolltolowerEx'>
				<view class="item"  v-for="(item, index)  in tableData" :key='index'  @click="getItemInfo(item)">
					<view class="nav">
						<image class="image" src="/subpackage-equipment/static/materials.png" mode=""></image>
						<text class="text color">{{item.subDeviceTypeName}}</text>
					</view>
					<view class="info">
						<view class="info-item">
							<view class="name">入库编号：</view>
							<view class="value">{{item.code}}</view>
						</view>
						<view class="info-item">
							<view class="name">入库数量：</view>
							<view class="value">{{item.num}}{{item.unit}}</view>
						</view>
						<view class="info-item">
							<view class="name">提交时间：</view>
							<view class="value">{{item.recordCreateDatetime}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import { getMaterialInWarehouseList } from "@/api/materials/materials.js"
	import baseInput from "@/components/baseInput/baseInput.vue"
	import mixins from "@/utils/mixins.js"
	export default {
		name: "entryLook",
		mixins: [mixins],
		components: {
			baseInput
		},
		data() {
			return {
				triggered: false,
				keyword:"",
				tableData:[],
				pagination:{
					total: "",
					pageSize: 10,
					currentPage: 1,
					totalPage:1,
				},
				flag:false,
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			getItemInfo(item){
				// uni.navigateTo({
				// 	url: `/pages/materials/materialsEntry/components/entryInfo?code=${item.code}&productionDate=${item.productionDate}&shelfLife=${item.shelfLife}&supplier=${item.supplier}&price=${item.price}&stationName=${item.stationName}&subDeviceTypeName=${item.subDeviceTypeName}&num=${item.num}&unit=${item.unit}`,
				// })
				uni.navigateTo({
					url: "/subpackage-materials/pages/materials/materialsEntry/components/entryInfo",
					success(res){
						res.eventChannel.emit("setData" , {
							data: item
						})
					}
				})
			},
			init(){
				this.getList();
			},
			getList(){
				if(this.flag){
					return
				}
				console.log('l',this.tableData.length)
				console.log('total',this.pagination.total)
				if(this.pagination.total !== "" &&  this.tableData.length >0  && this.tableData.length >= this.pagination.total ){
					uni.showToast({
						icon: "none",
						title: "到底了"
					})
					return
				}
				this.flag=true
				let _data = {
					currPage: this.pagination.currentPage,
					pageSize: this.pagination.pageSize,
					params: {
						code:this.keyword,
						requestMode:'app'
					}
				}
				getMaterialInWarehouseList(_data).then(res=>{
					if(res.success){
 						let list  = res.result.list.map(item=>({ ...item, recordCreateDatetime: this.getDate2(item.recordCreateDate)}))
						this.tableData = [...this.tableData, ...list]
						this.pagination.total = res.result.total
						this.pagination.totalPage=res.result.totalPage
					}
					this.flag=false
				})
			},
			inputChange(e){
				if(e){
				this.keyword=e
				}else {
					this.keyword=""
				}
				clearTimeout(this.time)
				this.time = setTimeout(()=>{
					this.pagination.currentPage = 1
					this.tableData=[]
					this.getList()
				},500)
			},
			scrolltolowerEx() {
				this.pagination.currentPage ++
				this.getList()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.entryLook{
		font-family: PingFang SC-Medium, PingFang SC;
		padding-top: 20rpx;
		.content-scoll{
			height: 65vh;
		}
		.content{
			padding-top: 40rpx;
		}
		.item{
			width: 100%;
			background: linear-gradient(180deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
			box-shadow: 0rpx 0rpx 34rpx 2rpx rgba(47, 128, 237, 0.1);
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 2rpx solid #EBF1FE;
			padding: 0rpx 34rpx;
			padding-bottom: 32rpx;
			box-sizing: border-box;
			margin-bottom: 30rpx;
			
			.nav{
				line-height: 88rpx;
				height: 88rpx;
				border-bottom: 2rpx dashed #E1E1E1;
				padding-bottom: 10rpx;
				
				.image{
					width: 70rpx;
					height: 70rpx;
					vertical-align: middle;
					margin-right: 30rpx;
				}
				.text{
					font-size: 30rpx;
					font-weight: bold;
					line-height: 95rpx;
					color: #F99C34;
				}
				.color{
					color: #5EAAFF;
				}
			}
			.info{
				padding-left: 15rpx;
				.info-item{
					display: flex;
					font-size: 28rpx;
					font-weight: 500;
					color: #445469;
					margin-top: 24rpx;
				}
			}
		}
	}
</style>
